import textwrap


str1 = textwrap.shorten("Hello world!",width=12)
print(str1)
str2 = textwrap.shorten("Hello world!",width=11)
print(str2)
str3 = textwrap.shorten("Hello world!",width=10,placeholder="...")
print(str3)

s = '''\
    hello
      world
    '''
print(repr(s))          # prints '    hello\n      world\n    '
print(repr(textwrap.dedent(s)))  # prints 'hello\n  world\n'